const Order = require('../model/order.model')
class OrderService {
  //创建订单
  async createOrder(order) {
    const res = await Order.create(order)
    return res.dataValues
    
  }

  //获取订单列表
  async findAllOrder(pageNum, pageSize, status) {
    const offset = (pageNum - 1) * pageSize
    const  limit = pageSize*1
    const {count,rows} = await Order.findAndCountAll({
      limit,
      offset,
      where: {
        status,
      },
      attributes: ['goods_info','total','status', 'order_number', 'createdAt', 'updatedAt']
    })
    return {
      pageNum,
      pageSize,
      total: count,
      list: rows
    }
  }

  //更新订单状态
  async updateOrder(id, status) {
    const res = await Order.update({status}, {
      where: {
        id
      }
    })
    return res[0] > 0
  }
}




module.exports = new OrderService() 